<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <link rel="stylesheet" href="docgen-resources/docgen.css" type="text/css">
  <meta name="generator" content="FreeMarker Docgen (DocBook 5)">
  <title>
    FreeMarker Manual - visit, recurse, fallback
  </title>
    <script type="text/javascript" src="docgen-resources/jquery.js"></script>
    <script type="text/javascript" src="docgen-resources/linktargetmarker.js"></script>
</head>
<body>

    <div class="navigation">
    <div class="breadcrumb">
<span class="breadcrumb">        You are here:
          <a href="index.html">Book</a>
            <b>></b>
          <a href="ref.html">Reference</a>
            <b>></b>
          <a href="ref_directives.html">Directive Reference</a>
            <b>></b>
          visit, recurse, fallback
</span>    </div>
    <div class="bookmarks">
<span class="bookmarks">Bookmarks:
<a href="alphaidx.html">Alpha. index</a>, <a href="gloss.html">Glossary</a>, <a href="dgui_template_exp.html#exp_cheatsheet">Expressions</a>, <a href="ref_builtins_alphaidx.html">?builtins</a>, <a href="ref_directive_alphaidx.html">#directives</a>, <a href="ref_specvar.html">.spec_vars</a>, <a href="app_faq.html">FAQ</a>, <a href="api/index.html">API</a>, <a href="../index.html">Home</a></span>    </div>
    <div class="pagers">
      <div class="pagersVerticalSpacer"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></div>
<div class="pagerButton"><a href="ref_specvar.html"><span class="hideA">Next page: </span>Special Variable Reference</a></div><div class="pagerButton"><a href="ref_directive_attempt.html">Previous page</a></div><div class="pagerButton"><a href="ref_directives.html">Parent page</a></div><div class="pagerButton"><a href="index.html">Contents</a></div>      <div class="pagersVerticalSpacer"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></div>
    </div>
    </div>

<div id="mainContent">

  
  
  
  
  <h1 class="rank_section1"
        id="pageTopTitle">
<a name="ref_directive_visit"></a>visit, recurse, fallback  </h1>
    
    <div class="toc">
      <p>
        <b>
            Page Contents
        </b>
      </p>
      
  <ul class="noMargin">
      <li>
        <a href="#autoid_123">Synopsis</a>
      </li>
      <li>
        <a href="#autoid_124">Description</a>
  <ul >
      <li>
        <a href="#autoid_125">Visit</a>
      </li>
      <li>
        <a href="#autoid_126">Recurse</a>
      </li>
      <li>
        <a href="#autoid_127">Fallback</a>
      </li>
  </ul>
      </li>
  </ul>
    </div>
    <a name="docgen_afterTheTOC"></a>
    
<a name="ref.directive.visit"></a>
            
  
  
  
  <h2 class="rank_section2"
        >
<a name="autoid_123"></a>Synopsis  </h2>


          <pre class="metaTemplate"><tt style="color: #A03D10">&lt;#visit <i style="color: #DD4400">node</i> using <i style="color: #DD4400">namespace</i>&gt;</tt>
or
<tt style="color: #A03D10">&lt;#visit <i style="color: #DD4400">node</i>&gt;</tt></pre>


          <pre class="metaTemplate"><tt style="color: #A03D10">&lt;#recurse <i style="color: #DD4400">node</i> using <i style="color: #DD4400">namespace</i>&gt;</tt>
or
<tt style="color: #A03D10">&lt;#recurse <i style="color: #DD4400">node</i>&gt;</tt>
or
<tt style="color: #A03D10">&lt;#recurse using <i style="color: #DD4400">namespace</i>&gt;</tt>
or
<tt style="color: #A03D10">&lt;#recurse&gt;</tt></pre>


          <pre class="metaTemplate"><tt style="color: #A03D10">&lt;#fallback&gt;</tt></pre>


          <p>Where:</p>

              <div class="itemizedlist">
<ul>
            <li>
              <tt style="color: #A03D10"><i style="color: #DD4400">node</i></tt>:
              Expression evaluates to a <a href="xgui_expose_dom.html">node
              variable</a>.
            </li>

            <li>
              <tt style="color: #A03D10"><i style="color: #DD4400">namespace</i></tt>: A
              <a href="dgui_misc_namespace.html">namespace</a>, or a
              sequence of namespaces. A namespace can be given with the
              namespace hash (a.k.a. gate hash), or with a string literal that
              store the path of template that could be imported. Instead of
              namespace hashes, you can use plain hashes as well.
            </li>
          </ul>    </div>

        
            
  
  
  
  <h2 class="rank_section2"
        >
<a name="autoid_124"></a>Description  </h2>


          <p>The <tt style="color: #A03D10">visit</tt> and <tt style="color: #A03D10">recurse</tt>
          directives are used for the recursive processing of trees. In
          practice, this will mostly be used for <a href="xgui.html">processing XML.</a></p>

          
              
  
  
  
  <h3 class="rank_section3"
        >
<a name="autoid_125"></a>Visit  </h3>


            <p>When you call <tt style="color: #A03D10">&lt;#visit
            <i style="color: #DD4400">node</i>&gt;</tt>, it looks for a
            user-defined directive (like a macro) to invoke that has the name
            deducted from the node's name
            (<tt style="color: #A03D10"><i style="color: #DD4400">node</i>?node_name</tt>) and
            namespace
            (<tt style="color: #A03D10"><i style="color: #DD4400">node</i>?node_namesoace</tt>).
            The rules of name deduction:</p>

                <div class="itemizedlist">
<ul>
              <li>
                <p>If the node doesn't support node namespaces (as text
                nodes in XML), then the directive name is simply the name of
                the node
                (<tt style="color: #A03D10"><i style="color: #DD4400">node</i>?node_name</tt>).
                <span style="color:#333399; font-style:italic">A node does not support node
                namespaces if the <tt style="color: #A03D10">getNodeNamespace</tt> method
                returns <tt style="color: #A03D10">null</tt>.</span></p>
              </li>

              <li>
                <p>If the node does support node namespaces (as element
                nodes in XML), then a prefix deduced from the node namespace
                maybe appended before the node name with a colon used as
                separator (e.g. <tt style="color: #A03D10">e:book</tt>). The prefix, and if
                there is a prefix used at all, depends on what prefixes has
                been registered with the <tt style="color: #A03D10">ns_prefixes</tt>
                parameter of the <tt style="color: #A03D10">ftl</tt> directive in the <a href="dgui_misc_namespace.html">FTL namespace</a> where
                <tt style="color: #A03D10">visit</tt> looks for the handler directive
                (which is not necessary the same as the FTL namespace where
                <tt style="color: #A03D10">visit</tt> was called from, as you will see
                later). Concretely, if there was no default namespace
                registered with <tt style="color: #A03D10">ns_prefixes</tt> then for nodes
                that does not belong to any namespace (<span style="color:#333399; font-style:italic">when <tt style="color: #A03D10">getNodeNamespace</tt>
                returns <tt style="color: #A03D10">&quot;&quot;</tt></span>) no prefix is used. If
                there was a default namespace registered with
                <tt style="color: #A03D10">ns_prefixes</tt> then for nodes that does not
                belong to any namespace prefix <tt style="color: #A03D10">N</tt> is used,
                and for nodes that belong to the default node namespace no
                prefix is used. Otherwise, in both case, the prefix associated
                to the node namespace with the <tt style="color: #A03D10">ns_prefixes</tt>
                is used. If there is not prefix associated to the node
                namespace of the node, then <tt style="color: #A03D10">visit</tt> simply
                behave as if there was no directive found with the proper
                name.</p>
              </li>
            </ul>    </div>


            <p>The node for which the user-defined directive was invoked is
            available for it as special variable <tt style="color: #A03D10">.node</tt>.
            Example:</p>

            <div align="left" class="programlisting"><table bgcolor="#D8D8D8" cellspacing="0" cellpadding="0" border="0"><tr valign="top"><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td></tr><tr><td width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td><table bgcolor="#D8D8D8" cellspacing="0" cellpadding="4" border="0" width="100%" style="margin: 0px"><tr><td><pre style="margin: 0px">
&lt;#-- Assume that nodeWithNameX?node_name is &quot;x&quot; --&gt;
&lt;#visit nodeWithNameX&gt;
Done.
&lt;#macro x&gt;
   Now I'm handling a node that has the name &quot;x&quot;.
   Just to show how to access this node: this node has ${.node?children?size} children.
&lt;/#macro&gt;&nbsp;<span style="font-size: 1pt"> </span></pre></td></tr></table></td><td width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td></tr><tr valign="top"><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td>      </tr>
</table>  </div>


            <p>The output will be something like:</p>

            <div align="left" class="programlisting"><table bgcolor="#CCFFCC" cellspacing="0" cellpadding="0" border="0"><tr valign="top"><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td></tr><tr><td width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td><table bgcolor="#CCFFCC" cellspacing="0" cellpadding="4" border="0" width="100%" style="margin: 0px"><tr><td><pre style="margin: 0px">
   Now I'm handling a node that has the name &quot;x&quot;.
   Just to show how to access this node: this node has 3 children.
Done.&nbsp;<span style="font-size: 1pt"> </span></pre></td></tr></table></td><td width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td></tr><tr valign="top"><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td>      </tr>
</table>  </div>


            <p>If one or more namespaces is specified using the optional
            <tt style="color: #A03D10">using</tt> clause, then <tt style="color: #A03D10">visit</tt>
            will look for the directives in those namespaces only, with the
            earlier specified namespaces in the list getting priority. If no
            <tt style="color: #A03D10">using</tt> clause is specified, the namespace or
            sequence of namespaces specified with the <tt style="color: #A03D10">using</tt>
            clause of the last uncompleted <tt style="color: #A03D10">visit</tt> call is
            reused. If there is no such pending <tt style="color: #A03D10">visit</tt> call,
            then the current namespace is used. For example, if you execute
            this template:</p>

            <div align="left" class="programlisting"><table bgcolor="#D8D8D8" cellspacing="0" cellpadding="0" border="0"><tr valign="top"><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td></tr><tr><td width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td><table bgcolor="#D8D8D8" cellspacing="0" cellpadding="4" border="0" width="100%" style="margin: 0px"><tr><td><pre style="margin: 0px">
&lt;#import &quot;n1.ftl&quot; as n1&gt;
&lt;#import &quot;n2.ftl&quot; as n2&gt;

&lt;#-- This will call n2.x (because there is no n1.x): --&gt;
&lt;#visit nodeWithNameX using [n1, n2]&gt;

&lt;#-- This will call the x of the current namespace: --&gt;
&lt;#visit nodeWithNameX&gt;

&lt;#macro x&gt;
  Simply x
&lt;/#macro&gt;&nbsp;<span style="font-size: 1pt"> </span></pre></td></tr></table></td><td width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td></tr><tr valign="top"><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td>      </tr>
</table>  </div>


            <p>and this is <tt style="color: #A03D10">n1.ftl</tt>:</p>

            <div align="left" class="programlisting"><table bgcolor="#D8D8D8" cellspacing="0" cellpadding="0" border="0"><tr valign="top"><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td></tr><tr><td width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td><table bgcolor="#D8D8D8" cellspacing="0" cellpadding="4" border="0" width="100%" style="margin: 0px"><tr><td><pre style="margin: 0px">
&lt;#macro y&gt;
  n1.y
&lt;/#macro&gt;&nbsp;<span style="font-size: 1pt"> </span></pre></td></tr></table></td><td width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td></tr><tr valign="top"><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td>      </tr>
</table>  </div>


            <p>and this is <tt style="color: #A03D10">n2.ftl</tt>:</p>

            <div align="left" class="programlisting"><table bgcolor="#D8D8D8" cellspacing="0" cellpadding="0" border="0"><tr valign="top"><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td></tr><tr><td width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td><table bgcolor="#D8D8D8" cellspacing="0" cellpadding="4" border="0" width="100%" style="margin: 0px"><tr><td><pre style="margin: 0px">
&lt;#macro x&gt;
  n2.x
  &lt;#-- This will call n1.y, becuase it inherits the &quot;using [n1, n2]&quot; from the pending visit call: --&gt;
  &lt;#visit nodeWithNameY&gt;
  &lt;#-- This will call n2.y: --&gt;
  &lt;#visit nodeWithNameY using .namespace&gt;
&lt;/#macro&gt;

&lt;#macro y&gt;
  n2.y
&lt;/#macro&gt;&nbsp;<span style="font-size: 1pt"> </span></pre></td></tr></table></td><td width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td></tr><tr valign="top"><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td>      </tr>
</table>  </div>


            <p>then this will print:</p>

            <div align="left" class="programlisting"><table bgcolor="#CCFFCC" cellspacing="0" cellpadding="0" border="0"><tr valign="top"><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td></tr><tr><td width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td><table bgcolor="#CCFFCC" cellspacing="0" cellpadding="4" border="0" width="100%" style="margin: 0px"><tr><td><pre style="margin: 0px">

  n2.x
  n1.y
  n2.y

  Simply x
 &nbsp;<span style="font-size: 1pt"> </span></pre></td></tr></table></td><td width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td></tr><tr valign="top"><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td>      </tr>
</table>  </div>


            <p>If <tt style="color: #A03D10">visit</tt> doesn't find a user-defined
            directive in either FTL namespaces with the name identical to the
            name deduced with the rules described earlier, then it tries to
            find an user-defined directive with name
            <tt style="color: #A03D10">@<i style="color: #DD4400">node_type</i></tt>, or if
            the node does not support node type property (i.e.
            <tt style="color: #A03D10"><i style="color: #DD4400">node</i>?node_type</tt>
            returns undefined variable), then with name
            <tt style="color: #A03D10">@default</tt>. For the lookup, it uses the same
            mechanism as was explained earlier. If it still doesn't find an
            user-defined directive to handle the node, then
            <tt style="color: #A03D10">visit</tt> stops template processing with error.
            Some XML specific node types have special handling in this regard;
            see: <a href="xgui_declarative_details.html">XML Processing Guide/Declarative XML Processing/Details</a>. Example:</p>

            <div align="left" class="programlisting"><table bgcolor="#D8D8D8" cellspacing="0" cellpadding="0" border="0"><tr valign="top"><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td></tr><tr><td width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td><table bgcolor="#D8D8D8" cellspacing="0" cellpadding="4" border="0" width="100%" style="margin: 0px"><tr><td><pre style="margin: 0px">
&lt;#-- Assume that nodeWithNameX?node_name is &quot;x&quot; --&gt;
&lt;#visit nodeWithNameX&gt;

&lt;#-- Assume that nodeWithNameY?node_type is &quot;foo&quot; --&gt;
&lt;#visit nodeWithNameY&gt;

&lt;#macro x&gt;
Handling node x
&lt;/#macro&gt;

&lt;#macro @foo&gt;
There was no specific handler for node ${node?node_name}
&lt;/#macro&gt;&nbsp;<span style="font-size: 1pt"> </span></pre></td></tr></table></td><td width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td></tr><tr valign="top"><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td>      </tr>
</table>  </div>


            <p>This would print:</p>

            <div align="left" class="programlisting"><table bgcolor="#CCFFCC" cellspacing="0" cellpadding="0" border="0"><tr valign="top"><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td></tr><tr><td width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td><table bgcolor="#CCFFCC" cellspacing="0" cellpadding="4" border="0" width="100%" style="margin: 0px"><tr><td><pre style="margin: 0px">
Handling node x
  
There was no specific handler for node y

 &nbsp;<span style="font-size: 1pt"> </span></pre></td></tr></table></td><td width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td></tr><tr valign="top"><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td>      </tr>
</table>  </div>

          

          
              
  
  
  
  <h3 class="rank_section3"
        >
<a name="autoid_126"></a>Recurse  </h3>


            <a name="ref.directive.recurse"></a>

            <p>The <tt style="color: #A03D10">&lt;#recurse&gt;</tt> directive is really
            syntactic sugar. It visits all children nodes of the node (and not
            the node itself). So, to write:</p>

            <div align="left" class="programlisting"><table bgcolor="#D8D8D8" cellspacing="0" cellpadding="0" border="0"><tr valign="top"><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td></tr><tr><td width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td><table bgcolor="#D8D8D8" cellspacing="0" cellpadding="4" border="0" width="100%" style="margin: 0px"><tr><td><pre style="margin: 0px">
&lt;#recurse <i>someNode</i> using <i>someLib</i>&gt;&nbsp;<span style="font-size: 1pt"> </span></pre></td></tr></table></td><td width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td></tr><tr valign="top"><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td>      </tr>
</table>  </div>


            <p>is equivalent to writing:</p>

            <div align="left" class="programlisting"><table bgcolor="#D8D8D8" cellspacing="0" cellpadding="0" border="0"><tr valign="top"><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td></tr><tr><td width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td><table bgcolor="#D8D8D8" cellspacing="0" cellpadding="4" border="0" width="100%" style="margin: 0px"><tr><td><pre style="margin: 0px">
&lt;#list <i>someNode</i>?children as <i>child</i>&gt;&lt;#visit <i>child</i> using <i>someLib</i>&gt;&lt;/#list&gt;&nbsp;<span style="font-size: 1pt"> </span></pre></td></tr></table></td><td width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td></tr><tr valign="top"><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td>      </tr>
</table>  </div>


            <p>However, target node is optional in the
            <tt style="color: #A03D10">recurse</tt> directive. If the target node is
            unspecified, it simply uses the <tt style="color: #A03D10">.node</tt>. Thus,
            the terse instruction <tt style="color: #A03D10">&lt;#recurse&gt;</tt> is
            equivalent to:</p>

            <div align="left" class="programlisting"><table bgcolor="#D8D8D8" cellspacing="0" cellpadding="0" border="0"><tr valign="top"><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td></tr><tr><td width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td><table bgcolor="#D8D8D8" cellspacing="0" cellpadding="4" border="0" width="100%" style="margin: 0px"><tr><td><pre style="margin: 0px">
&lt;#list .node?children as child&gt;&lt;#visit child&gt;&lt;/#list&gt;&nbsp;<span style="font-size: 1pt"> </span></pre></td></tr></table></td><td width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td></tr><tr valign="top"><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td>      </tr>
</table>  </div>


            <p>As a side comment for those who are familiar with XSLT,
            <tt style="color: #A03D10">&lt;#recurse&gt;</tt> is pretty much exactly
            analogous to the <tt style="color: #A03D10">&lt;xsl:apply-templates/&gt;</tt>
            instruction in XSLT.</p>
          

          
              
  
  
  
  <h3 class="rank_section3"
        >
<a name="autoid_127"></a>Fallback  </h3>


            <a name="ref.directive.fallback"></a>

            <p>As you could learn earlier, in the documentation of the
            <tt style="color: #A03D10">visit</tt> directive, the user-defined directive
            that handles the node is maybe searched in multiple FTL
            name-spaces. The <tt style="color: #A03D10">fallback</tt> directive can be used
            in a user-defined directive that was invoked to handle a node. It
            directs FreeMarker to continue the searching for the user-defined
            directive in the further name-spaces (that is, in the name-spaces
            that are after the name-space of the currently invoked
            user-defined directive in the list of name-spaces). If a handler
            for the node is found then it is invoked, otherwise
            <tt style="color: #A03D10">fallback</tt> does nothing.</p>

            <p>A typical usage of this to write customization layer over a
            handler library, that sometimes passes the handling to the
            customized library:</p>

            <div align="left" class="programlisting"><table bgcolor="#D8D8D8" cellspacing="0" cellpadding="0" border="0"><tr valign="top"><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td></tr><tr><td width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td><table bgcolor="#D8D8D8" cellspacing="0" cellpadding="4" border="0" width="100%" style="margin: 0px"><tr><td><pre style="margin: 0px">
&lt;#import &quot;/lib/docbook.ftl&quot; as docbook&gt;

&lt;#--
  We use the docbook library, but we override some handlers
  in this namespace.
--&gt;
&lt;#visit document using [.namespace, docbook]&gt;

&lt;#--
  Override the &quot;programlisting&quot; handler, but only in the case if
  its &quot;role&quot; attribute is &quot;java&quot;
--&gt;
&lt;#macro programlisting&gt;
  &lt;#if .node.@role[0]!&quot;&quot; == &quot;java&quot;&gt;
    &lt;#-- Do something special here... --&gt;
    ...
  &lt;#else&gt;
    &lt;#-- Just use the original (overidden) handler --&gt;
    &lt;#fallback&gt;
  &lt;/#if&gt;
&lt;/#macro&gt;&nbsp;<span style="font-size: 1pt"> </span></pre></td></tr></table></td><td width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td></tr><tr valign="top"><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td>      </tr>
</table>  </div>

          
          
</div>

    <div class="navigation">
    <div class="pagers">
      <div class="pagersVerticalSpacer"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></div>
<div class="pagerButton"><a href="ref_specvar.html"><span class="hideA">Next page: </span>Special Variable Reference</a></div><div class="pagerButton"><a href="ref_directive_attempt.html">Previous page</a></div><div class="pagerButton"><a href="ref_directives.html">Parent page</a></div><div class="pagerButton"><a href="index.html">Contents</a></div>      <div class="pagersVerticalSpacer"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></div>
    </div>
    <div class="breadcrumb">
<span class="breadcrumb">        You are here:
          <a href="index.html">Book</a>
            <b>></b>
          <a href="ref.html">Reference</a>
            <b>></b>
          <a href="ref_directives.html">Directive Reference</a>
            <b>></b>
          visit, recurse, fallback
</span>    </div>
    </div>

<table border=0 cellspacing=0 cellpadding=0 width="100%">
    <tr>
      <td colspan=2><img src="docgen-resources/img/none.gif" width=1 height=8 alt=""></td>
    <tr>
      <td align="left" valign="top"><span class="smallFooter">
            FreeMarker Manual -- For FreeMarker 2.3.20
            <br>
          HTML generated: 2013-06-27 20:54:33 GMT
      </span></td>
      <td align="right" valign="top"><span class="smallFooter">
          <a href="http://www.xmlmind.com/xmleditor/">
            <img src="docgen-resources/img/xxe.gif" alt="Edited with XMLMind XML Editor">
          </a>
      </span></td>
    </tr>
</table>
  <!-- Put pre-loaded images here: -->
  <div style="display: none">
    <img src="docgen-resources/img/linktargetmarker.gif" alt="Here!" />
  </div>
</body>
</html>

